package Str;

import java.util.Arrays;

/**
 * 作者:hfj
 * 功能:242.有效的字母异位词
 * 日期: 2025/10/28 20:14
 */
public class IsAnagram {

    public static void main(String[] args) {
        String s = "anagram";
        String t = "nagaram";
        System.out.println(isAnagram(s,t));
    }

    public static boolean isAnagram(String s, String t) {
        if (s.length() != t.length()){
            return false;
        }
        char[] char_s = s.toCharArray();
        char[] char_t = t.toCharArray();

        Arrays.sort(char_s);
        Arrays.sort(char_t);
        s = new String(char_s);
        t = new String(char_t);
        if (s.equals(t)){
            return true;
        }
        return false;
    }
}
